/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hhf.logger;

import java.lang.reflect.Field;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author François
 */
public class LoggerProducer {
	@Produces
	public Logger getLogger(InjectionPoint ip) {
		Class c = ip.getMember().getDeclaringClass();
		String loggerName = c.getName();
		String fieldName =  ip.getMember().getName();
		try {
			Field f = c.getDeclaredField(fieldName);
			if(f.isAnnotationPresent(LoggerName.class)) {
				LoggerName ln = f.getAnnotation(LoggerName.class);
				loggerName = ln.value();
			}
		} catch (NoSuchFieldException ex) {
		} catch (SecurityException ex) {
		}
		Logger logger = LoggerFactory.getLogger(loggerName);
		return logger;
	}
}
